package cn.lhl.flowable.task;

import cn.hutool.crypto.SecureUtil;
import cn.lhl.flowable.workflow.LCDuoRenHuiQian;
import cn.lhl.flowable.workflow.LCQingJia;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RuntimeService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.crypto.SecretKey;
import java.util.*;

@Component
public class Task {

    @Resource
    private ProcessEngine processEngine;
    @Resource
    private RuntimeService runtimeService;

    @Resource
    private  LCQingJia lcQingJia;
    @Resource
    private  LCDuoRenHuiQian lcDuoRenHuiQian;



    @PostConstruct
    public void main_ini() {
        //流程部署
        lcQingJia.Deployment();

        //会签的
       // lcDuoRenHuiQian.Deployment();

    }




    //0/2 * * * * ?   表示每2秒 执行任务
    //0 0/2 * * * ?    表示每2分钟 执行任务
    //0 0/30 9-17 * * ?   朝九晚五工作时间内每半小时
    @Scheduled(cron = "0 0/1 * * * ?")
    public void mock_star() {
        //发起
        Map<String, Object> variables =new HashMap<>();
        variables.put("useid",99999);
        variables.put("msg","杜紫藤");
        variables.put("assignee",99999);
        variables.put("candidateGroups", Arrays.asList("mageger","mageger2","mageger3"));

        lcQingJia.start(variables);

    }


    //0/2 * * * * ?   表示每2秒 执行任务
    //0 0/2 * * * ?    表示每2分钟 执行任务
    //0 0/30 9-17 * * ?   朝九晚五工作时间内每半小时
    @Scheduled(cron = "0/5 * * * * ?")
    public void mock_chaDaiBan() {
        //查待办
        System.out.println("查待办>>>>>>");
        List<String> daiban = lcQingJia.daiban();
        daiban.forEach(System.out::println);

    }

    @Scheduled(cron = "0/7 * * * * ?")
    public void mock_nestnode() {
        //查下节点
        System.out.println("查下节点>>>>>>");
        lcQingJia.nextNodeOfTodo();

    }

    //@Scheduled(cron = "0 0/1 * * * ?")
    public void mock_shenPi_tongyi() {
        //执行审批同意
        System.out.println("执行审批同意>>>>>>");
        lcQingJia.tongyi();

    }

    //@Scheduled(cron = "0/20 * * * * ?")
    public void mock_chaLiShi() {
        //查历史流程 已经完成的流程实例
        System.out.println("查历史流程>>>>>>");
        lcQingJia.chaLiShiLiuCheng();
        lcQingJia. chaLiShiTask("mageger");

    }

    /**互斥网关（Exclusive Gateway），又称排他网关，他有且仅有一个有效出口，
     * 并行网关（Parallel Gateway），他的所有出口都会被执行，
     * 包容性网关（Inclusive Gateway），只要满足条件的出口都会执行，
     * 事件网关
     *
     * */


    //>>>>>>>>>多人会签的>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //@Scheduled(cron = "0 0/1 * * * ?")
    public void mock_lcDuoRenHuiQian_star() {
        //发起
        lcDuoRenHuiQian.start();

    }


    //@Scheduled(cron = "0/5 * * * * ?")
    public void mock_lcDuoRenHuiQian_chaDaiBan() {
        //查待办
        System.out.println("查待办>>>>>>");
        List<String> daiban = lcDuoRenHuiQian.daiban();
        daiban.forEach(System.out::println);

    }


    //@Scheduled(cron = "0/20 * * * * ?")
    public void mock_shenPi_tongguo() {
        //执行审批同意
        System.out.println("执行审批同意>>>>>>");
        lcDuoRenHuiQian.tongyi("use1");
        lcDuoRenHuiQian.tongyi("use2");

    }

    //@Scheduled(cron = "0/20 * * * * ?")
    public void mock_lcDuoRenHuiQian_chaLiShi() {
        //查历史流程 已经完成的流程实例
        System.out.println("查历史流程>>>>>>");
        lcDuoRenHuiQian.chaLiShiLiuCheng();
        lcDuoRenHuiQian. chaLiShiTask("mmmmm");

    }


    public static void main(String[] args) {
        String data="需要解解密的串";
        //获取对称秘钥
        SecretKey secretKey = SecureUtil.aes().getSecretKey();
        byte[] encoded = secretKey.getEncoded();
        //byte秘钥转字符串
        String encoded___key = Base64.getEncoder().encodeToString(encoded);
        System.out.println("Base64strKey:"+encoded___key);
        //字符串转byte秘钥
        byte[] decoded_key = Base64.getDecoder().decode(encoded___key);
        System.out.println("Base64_byteKey:" + decoded_key);

        System.out.println("密钥:"+encoded___key);

        String encString = SecureUtil.aes(decoded_key).encryptHex(data);
        System.out.println("加密后:"+encString);

        String decStr = SecureUtil.aes(decoded_key).decryptStr(encString);
        System.out.println("解密后:"+decStr);
    }

}
